/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tutwiz.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

/**
 *
 * @author danielwirdehall
 */

@Entity(name="tutorialUser")
public class User implements Serializable {

    // Variables
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Long id;
    
    @Column(nullable=false, unique=true)
    private String name;
    
    @Column(nullable=false)
    private String password;
    
    @Column(nullable=false)
    private String email;
    
    private String website;
    
    @Temporal(TemporalType.DATE)
    private Date createdAt;
    //private long modifiedAt;

    // References
    @OneToMany(mappedBy="createdBy", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    private List<Tutorial> tutorials = new ArrayList<Tutorial>();
    
    @OneToMany(mappedBy="createdBy", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    private List<Comment> comments = new ArrayList<Comment>();
    
    @OneToMany(mappedBy="createdBy", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    private List<Vote> votes = new ArrayList<Vote>();
    
    public User() {
    }

    public User(String name, String password, String email) {
        this(name, password, email, null);
    }
    
    public User(String name, String password, String email, String website) {
        this.name = name;
        this.password = password;
        this.email = email;
        this.website = website;
        this.createdAt = Calendar.getInstance().getTime();
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public long getID() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getWebsite() {
        return website;
    }

    public void setWebsite(String website) {
        this.website = website;
    }

    public void addTutorial(Tutorial t) {
        tutorials.add(t);
        //throw new UnsupportedOperationException("Not yet implemented");
    }

    public List<Tutorial> getTutorials() {
        return tutorials;
    }

    public void setTutorials(List<Tutorial> tutorials) {
        this.tutorials = tutorials;
    }
}
